from rest_framework import serializers

from vouchers.models import *


class AliDiscountCouponModelSerializer(serializers.ModelSerializer):

    class Meta:
        model = AliDiscountCoupon
        fields = ['id', 'activity_name', 'floor_amount', 'coupon_type']


class AliFlipCARDSListModelSerializer(serializers.ModelSerializer):

    open_status_str = serializers.CharField(source='get_open_status_display', read_only=True)
    result = serializers.SerializerMethodField(read_only=True)

    class Meta:
        model = AliFlipCARDS
        fields = ['id', 'open_status', 'open_status_str', 'result']

    def get_result(self, obj):
        data = {}
        if obj.open_status == 1:
            return {}
        if obj.win_type == 3:
            data['amount'] = ''
            data['msg'] = ''
            data['win_type'] = 3
            data['name'] = ''
            return data
        elif obj.win_type == 2:
            data['amount'] = obj.amount
            data['msg'] = ''
            data['win_type'] = 2
            data['name'] = '邮储银行消费红包'
            return data
        else:
            data['amount'] = obj.alidiscountcoupon.amount
            data['msg'] = obj.alidiscountcoupon.floor_amount
            data['win_type'] = 1
            data['name'] = obj.alidiscountcoupon.activity_name
            return data
